function Food(el) {

    // 1.保存地图对象
    this.el = el

    // 2.保存食物属性
    this.len = 20
    this.foodObj = null
    this.foodX = 0
    this.foodY = 0
}

Food.prototype.create = function() {
    
    // 1-创建div标签对象
    let divObj = document.createElement("div")

    // 2-设置样式
    divObj.style.width = this.len + "px"
    divObj.style.height = this.len + "px"
    divObj.style.background = "green"
    divObj.style.borderRadius="50% 50%"
    divObj.style.position = "absolute"

    // 单独保存食物的对象
    this.foodObj = divObj
   
    // 3-在页面展示
    this.el.appendChild(divObj)
    // 4-默认移动食物
    this.move()
}

Food.prototype.move = function() {
    // 留心：每次打开页面刷新 食物位置都会不一样
   

    let foodXMaxNum = this.el.clientWidth / this.len - 1  //食物不能超过盒子 
    let foodYMaxNum = this.el.clientHeight / this.len - 1
   
    // 随机公式： Math.floor(Math.random()* (max-min+1)+min) 
    // 坐标 = 随机个数 * 每个宽度
    this.foodX = Math.floor(Math.random() * (foodXMaxNum-0+1)+0) * this.len
    this.foodY = Math.floor(Math.random() * (foodYMaxNum-0+1)+0) * this.len

    this.foodObj.style.left = this.foodX + "px"
    this.foodObj.style.top = this.foodY + "px"
}